#include "enemy.h"
#include "qgraphicsscene.h"
#include<bullet.h>
enemy::enemy() {}

enemy::enemy(qreal x, qreal y,bool flipHorizontal)
{
    this->x=x;
    this->y=y;
    setPos(x,y);
    if(flipHorizontal==false){
        enemypoint=right;

    }
    else if(flipHorizontal==true){
        enemypoint=left;
    }

    connect(attacktimer, &QTimer::timeout, this, &enemy::attack);
    attacktimer->start(5000);
}

enemy::~enemy()
{

}

enemy::enemy(qreal x, qreal y, bool flipHorizontal, QGraphicsScene *scene)
{
    scene->addItem(this);
    this->x=x;
    this->y=y;
    setPos(x,y);
    if(flipHorizontal==false){
        enemypoint=right;

    }
    else if(flipHorizontal==true){
        enemypoint=left;
    }

    connect(attacktimer, &QTimer::timeout, this, &enemy::attack);
    attacktimer->start(5000);
    setData(iscollision,true);
    setData(ObjectType,3);
}


void enemy::attack()
{
    bullet *Bullet=new bullet();
    Bullet->setData(ObjectType,3);
    Bullet->setData(iscollision,true);
    if(enemypoint==2){

        Bullet->setx(x + pixmap().width());
        Bullet->sety(y + pixmap().height() / 2 - Bullet->pixmap().height() / 2);
        Bullet->setvelocity(100);
    }
    else{ Bullet->setx(x - Bullet->pixmap().width());
        Bullet->sety(y + pixmap().height() / 2 - Bullet->pixmap().height() / 2);
        Bullet->setvelocity(-100);
    }
    scene()->addItem(Bullet);
}


